#ifndef __DISPLAY_H__
#define __DISPLAY_H__

/*****************************************************************************/
/* Include Files */

#include "Common.h"

/*****************************************************************************/
/* Macro Definitions */

#define RGB565(R, G, B) \
    (((TUINT16) ((R) >> 3)) << 11) + (((TUINT16) ((G) >> 2)) << 5) + ((TUINT16) ((B) >> 3))

#define RGB555_TO_RGB565(X) \
    ((((X)&0x7FE0) << 1)|((X)&0x003F))

#define	COLOR_BLACK		RGB565(0, 0, 0)
        
#define	COLOR_DRED		RGB565(64, 0, 0)
#define	COLOR_DGREEN	RGB565(0, 64, 0)
#define	COLOR_DBLUE		RGB565(0, 0, 64)

#define	COLOR_DYELLOW	RGB565(64, 64, 0)
#define	COLOR_DPURPLE	RGB565(64, 0, 64)
#define	COLOR_DDIAN		RGB565(0, 64, 64)
        
#define	COLOR_GRAY		RGB565(64, 64, 64)
        
#define	COLOR_RED		RGB565(255, 0, 0)
#define	COLOR_GREEN		RGB565(0, 255, 0)
#define	COLOR_BLUE		RGB565(0, 0, 255)
        
#define	COLOR_YELLOW	RGB565(255, 255, 0)
#define	COLOR_PURPLE	RGB565(255, 0, 255)
#define	COLOR_DIAN		RGB565(0, 255, 255)
        
#define	COLOR_WHITE		RGB565(255, 255, 255)
/*****************************************************************************/
/* Type Definitions */

/* Font Type */
typedef enum
{
    FONT_NONE,
#ifdef SUPPORT_FONT_12
    FONT_TYPE_12,
#endif /*SUPPORT_FONT_16*/
#ifdef SUPPORT_FONT_16
    FONT_TYPE_16,
#endif /*SUPPORT_FONT_16*/
#ifdef SUPPORT_FONT_24
    FONT_TYPE_24,
#endif /*SUPPORT_FONT_24*/
} T_FONT_TYPE;

/* Icon ID */
typedef enum
{
    ICON_UP_ARROW    = 0,
    ICON_DOWN_ARROW  = 1,
    ICON_LEFT_ARROW  = 2,
    ICON_RIGHT_ARROW = 3,
} T_ICON_ID;

/* Display Layer */
typedef enum
{
#ifdef SUPPORT_PRIMARY_LAYER
    DISPLAY_LAYER_PRIMARY,
#endif /*SUPPORT_PRIMARY_LAYER*/
#ifdef SUPPORT_OSD0
    DISPLAY_LAYER_OSD0,
#endif /*SUPPORT_OSD0*/
#ifdef SUPPORT_OSD1
    DISPLAY_LAYER_OSD1,
#endif /*SUPPORT_OSD1*/
    Num_Display_Layers
} T_LAYER_TYPE;

/*****************************************************************************/
/* Function Prototypes */

#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus*/

TINT32 Display_Initialize(void);

void Display_Cleanup(void);

#ifdef SUPPORT_PRIMARY_LAYER
TINT32 Display_Update_Primary(const void* frame_data,
                              TUINT32     input_width,
                              TUINT32     input_height,
                              TUINT32     output_width,
                              TUINT32     output_height);

TINT32 Display_Set_PrimaryFrameBuffer(void* frame_buffer);
#endif /*SUPPORT_PRIMARY_LAYER*/

TINT32 Display_Set_DefaultLayer(T_LAYER_TYPE layer);

TUINT16* Display_Get_CurrentFrameBuffer(void);

void Display_Set_Color(TUINT16 foreground_color,
                       TUINT16 background_color);

void Display_Get_Color(TUINT16* foreground_color,
                       TUINT16* background_color);

TINT32 Display_Set_Font(T_FONT_TYPE type);

T_FONT_TYPE Display_Get_Font(void);

TUINT32 Display_Get_FontWidth(void);

TUINT32 Display_Get_FontHeight(void);

TUINT32 Display_Get_DisplayWidth(void);

TUINT32 Display_Get_DisplayHeight(void);

TINT32 Display_Clear(TUINT16* frame_buffer);

TINT32 Display_Print_Char(TUINT32  x,
                          TUINT32  y,
                          TUINT8   data,
                          TUINT16* frame_buffer);

TINT32 Display_Print_String(TUINT32       x,
                            TUINT32       y,
                            const TUINT8* data,
                            TUINT16*      frame_buffer);
TINT32 Display_Print_DecNumber(TUINT32  x,
                               TUINT32  y,
                               TUINT32  length,
                               TUINT32  value,
                               TUINT16* frame_buffer);
TINT32 Display_Print_HexNumber(TUINT32  x,
                               TUINT32  y,
                               TUINT32  length,
                               TUINT32  value,
                               TUINT16* frame_buffer);

TINT32 Display_Print_Icon(TUINT32   x,
                          TUINT32   y,
                          T_ICON_ID icon_id,
                          TUINT16*  frame_buffer);

TINT32 Display_Draw_Pixel(TUINT32  x,
                          TUINT32  y,
                          TUINT16  color,
                          TUINT16* frame_buffer);

TINT32 Display_Draw_Line(TUINT32  x1,
                         TUINT32  y1,
                         TUINT32  x2,
                         TUINT32  y2,
                         TUINT16  color,
                         TUINT16* frame_buffer);

TINT32 Display_Draw_Rectangle(TUINT32  x1,
                              TUINT32  y1,
                              TUINT32  x2,
                              TUINT32  y2,
                              TUINT16  color,
                              TUINT16* frame_buffer);

TINT32 Display_Fill_Block(TUINT32  x,
                          TUINT32  y,
                          TUINT32  width,
                          TUINT32  height,
                          TUINT16  color,
                          TUINT16* frame_buffer);

TINT32 Display_BitBlt(TUINT32        x,
                      TUINT32        y,
                      TUINT32        width,
                      TUINT32        height,
                      const TUINT16* data,
                      TUINT16*       frame_buffer);

#ifdef SUPPORT_PWM_CTRL
TINT32 Display_Initialize_PWM(void);

void Display_Cleanup_PWM(void);

TINT32 Display_Set_PWM(TUINT16 pwm_value);

TINT32 Display_Set_PWMFreq(TUINT32 pwm_freq);
#endif /*SUPPORT_PWM_CTRL*/

#ifdef __cplusplus
}
#endif /*__cplusplus*/

/*****************************************************************************/
/* End of File */

#endif /*__DISPLAY_H__*/
